#include "SkyObject.h"
int SkyObject::sky_list_name=0;
int SkyObject::cloud_list_name=0;
bool SkyObject::compiled = false;

SkyObject::SkyObject()
{
}

SkyObject::~SkyObject(){}


void SkyObject::Init() 
{
   
    Rang = 0.0;
    if (!compiled) LoadLists();
    
}

void SkyObject::LoadLists()
{
    sky_list_name = glGenLists(1);
    glNewList(sky_list_name,GL_COMPILE);
        glEnable(GL_TEXTURE_2D);
        glScalef(1.0, 1.8, 1.0);
        glRotatef(90, 1, 0, 0);
        glBindTexture(GL_TEXTURE_2D,state->th->texNames[TEX_SKY]);
        gluSphere(state->quad_obj,SKY_DIM,20,20);                
        glDisable(GL_TEXTURE_2D);
    glEndList();

    //lista per le nuvole
    cloud_list_name = glGenLists(1);
    glNewList(cloud_list_name,GL_COMPILE);
        //il blending
        glColor4f(0.50f, 1.0f, 1.0f, 0.5);     
        glBlendFunc(GL_SRC_ALPHA,GL_ONE);       
        glEnable(GL_BLEND);   
        glEnable(GL_TEXTURE_2D);
            glBindTexture(GL_TEXTURE_2D,state->th->texNames[TEX_NUV]);
            gluSphere(state->quad_obj,SKY_DIM-30,20,20);
        glDisable(GL_TEXTURE_2D);
        glDisable(GL_BLEND);
        
    glEndList();
compiled = true;
}



void SkyObject::Draw(){

glPushMatrix();
    glTranslatef(-state->cam_posX,-state->cam_posY,-state->cam_posZ);
    glCallList(sky_list_name);
    
    //ruoto l'angolo delle nuvole
    glRotatef(Rang, 0, -0.4, 1);         
    glCallList(cloud_list_name);
glPopMatrix();
}

  
void SkyObject::DoIdle()
{
  Rang = Rang + 0.02;    
}


